<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //预解析先把程序里所有的var function提到前面，再代码执行
        // var num = 10;
        // fun();
        // function fun() {
        //     console.log(num);
        //     var num = 20;
        // }     //案例1，结果输出undefined

        var num1 = 10;
        function fn() {
            console.log(num1);  //输出undefined
            var num1 = 20;
            console.log(num1);   //输出20
        }
        fn();


        // var a = 18;
        // f1();
        // function f1() {
        //     var b = 9;
        //     console.log(a);  //undefined
        //     console.log(b);   //9
        //     var a = '123';
        // }



        f1();
        console.log(c);//9
        console.log(b);//9
        console.log(a);//undefined
        function f1() {
            var a = b = c = 9;  //相当于var a = 9;b =9,c=9;   所以b,c没有声明是直接赋值，当全局变量看
            //var a = 9, b = 9, c = 9; //集体声明   //相当于var a=9,var b=9, var c=9;
            console.log(a);//9
            console.log(b);//9
            console.log(c);//9
        }

    </script>
</head>

<body>

</body>

</html>